<#import "xml_recurse.ftl" as xml_re>
<#import "object_recurse.ftl" as obj_re>
<#import "name_recurse.ftl" as name_re>
{curl 4.0 package}
{curl-file-attributes character-encoding = "${doc.root.@encoding}"}

<#assign docno = doc.root.@docno>
{package COM.CURL.WSDL.Oscar${docno}Contract,
    {compiler-directives careful? = true},
    wsdl="file:///c:/OSCAR/oscar/app/webserver/curl2.0_dummy/Oscar${docno}Contract.wsdl"}

{import * from COM.CURL.WSDK.SOAP}
{include "wls-conf.scurl"}
{define-class public Oscar${docno} {inherits WSDLHTTPRPCPostClient}

  {method public {client-requestwith-return ${docno?lower_case}-input:${docno}input}:(${docno?lower_case}-output:${docno}output)
    
    let constant (responses:{Array-of any},
         headers:#${"{Array-of any}"},
         header-roles:#${"{Array-of #String}"},
         header-must-understands:#${"{Array-of bool}"},
         root-attributes:#${"{Array-of XMLAttribute})="}
        {self.soap-caller.call
            self.service-location,
            {{Array-of any}
                ${docno?lower_case}-input
            },
            {{Array-of #XMLName}
                {XMLName "http://temp.openuri.org/Oscar/${docno}.xsd", "${docno}input"}
            },
            {{Array-of SOAPObjectType}
                {SOAPObjectType
                    xml-type = {XMLName "http://temp.openuri.org/Oscar/${docno}.xsd", "${docno}input"},
                    curl-type = ${docno}input,
                    nillable? = true
                }
            },
            {{Array-of #XMLName}
                {XMLName "http://temp.openuri.org/Oscar/${docno}.xsd", "${docno}output"}
            },
            {{Array-of SOAPObjectType}
                {SOAPObjectType
                    xml-type = {XMLName "http://temp.openuri.org/Oscar/${docno}.xsd", "${docno}output"},
                    curl-type = ${docno}output,
                    nillable? = true
                }
            },
            null,
            soap-action = "http://www.openuri.org/clientRequestwithReturn",
            request-operation = {XMLName "http://www.openuri.org/", "clientRequestwithReturn"},
            response-operation = {XMLName "http://www.openuri.org/", "clientRequestwithReturnResponse"},
            rpc-style? = false,
            write-type-attribute? = false,
            write-encoding-attribute? = false
        }    
    {return
        responses[0] asa ${docno}output
    }
  }
  
  
  {method public {async-client-requestwith-return ${docno?lower_case}-input:${docno}input, event-handler:EventHandler, ...:EventHandler}:SOAPHTTPRPCPostAsyncWorker
    {return
        {self.soap-caller.async-call
            self.service-location,
            {{Array-of any}
                ${docno?lower_case}-input
            },
            {{Array-of #XMLName}
                {XMLName "http://temp.openuri.org/Oscar/${docno}.xsd", "${docno}input"}
            },
            {{Array-of SOAPObjectType}
                {SOAPObjectType
                    xml-type = {XMLName "http://temp.openuri.org/Oscar/${docno}.xsd", "${docno}input"},
                    curl-type = ${docno}input,
                    nillable? = true
                }
            },
            {{Array-of #XMLName}
                {XMLName "http://temp.openuri.org/Oscar/${docno}.xsd", "${docno}output"}
            },
            {{Array-of SOAPObjectType}
                {SOAPObjectType
                    xml-type = {XMLName "http://temp.openuri.org/Oscar/${docno}.xsd", "${docno}output"},
                    curl-type = ${docno}output,
                    nillable? = true
                }
            },
            null,
            soap-action = "http://www.openuri.org/clientRequestwithReturn",
            request-operation = {XMLName "http://www.openuri.org/", "clientRequestwithReturn"},
            response-operation = {XMLName "http://www.openuri.org/", "clientRequestwithReturnResponse"},
            rpc-style? = false,
            write-type-attribute? = false,
            write-encoding-attribute? = false,
            event-handler,
            ...
        }
    }
  }
  
  {method public {register-types
                 }:(type-mapper:SOAPTypeMapper,
                    element-name-to-xml-type:SOAPElementNameToXMLTypeMapper,
                    xml-type-to-curl-type:SOAPXMLTypeToCurlTypeMapper,
                    curl-type-to-xml-type:SOAPCurlTypeToXMLTypeMapper,
                    xml-type-to-element-name:SOAPXMLTypeToElementNameMapper
                   )
    let constant type-mapper:DefaultSOAPTypeMapper =
        {DefaultSOAPTypeMapper}
    let constant element-name-to-xml-type:DefaultSOAPElementNameToXMLTypeMapper =
        {DefaultSOAPElementNameToXMLTypeMapper}
    let constant xml-type-to-curl-type:DefaultSOAPXMLTypeToCurlTypeMapper =
        {DefaultSOAPXMLTypeToCurlTypeMapper}
    let constant curl-type-to-xml-type:DefaultSOAPCurlTypeToXMLTypeMapper =
        {DefaultSOAPCurlTypeToXMLTypeMapper}
    let constant xml-type-to-element-name:DefaultSOAPXMLTypeToElementNameMapper =
        {DefaultSOAPXMLTypeToElementNameMapper}
    {do
        let constant soap-struct-marshaler:SOAPStructMarshaler =
            {SOAPStructMarshaler
                {SOAPObjectType
                    element-name = {XMLName "http://temp.openuri.org/Oscar/AuthorizationInfo.xsd", "AuthorizationInfo"},
                    xml-type = {XMLName "http://temp.openuri.org/Oscar/AuthorizationInfo.xsd", "AuthorizationInfoType"},
                    curl-type = AuthorizationInfoType,
                    nillable? = true
                },
                {{Array-of #XMLName}
                    {XMLName "http://temp.openuri.org/Oscar/AuthorizationInfo.xsd", "login_id"},
                    {XMLName "http://temp.openuri.org/Oscar/AuthorizationInfo.xsd", "login_password"},
                    {XMLName "http://temp.openuri.org/Oscar/AuthorizationInfo.xsd", "screen_id"}
                },
                {{Array-of SOAPObjectType}
                    {SOAPObjectType
                        xml-type = {XMLName SOAPTypeMapper.xml-schema-uri, "string"},
                        curl-type = String
                    },
                    {SOAPObjectType
                        xml-type = {XMLName SOAPTypeMapper.xml-schema-uri, "string"},
                        curl-type = String
                    },
                    {SOAPObjectType
                        xml-type = {XMLName SOAPTypeMapper.xml-schema-uri, "string"},
                        curl-type = String
                    }
                },
                {{Array-of String}
                    "login-id",
                    "login-password",
                    "screen-id"
                },
                element-name-to-xml-type = element-name-to-xml-type,
                xml-type-to-curl-type = xml-type-to-curl-type,
                curl-type-to-xml-type = curl-type-to-xml-type,
                xml-type-to-element-name = xml-type-to-element-name
            }
        {soap-struct-marshaler.register
            type-mapper = type-mapper,
            element-name-to-xml-type-mapper = element-name-to-xml-type,
            xml-type-to-curl-type-mapper = xml-type-to-curl-type,
            curl-type-to-xml-type-mapper = curl-type-to-xml-type,
            xml-type-to-element-name-mapper = xml-type-to-element-name
        }
    }
    {do
        let constant array-marshaler:SOAPArrayMarshaler =
            {SOAPArrayMarshaler.from-element-type-array
                {{Array-of SOAPObjectType}
                    {SOAPObjectType
                        element-name = {XMLName "http://temp.openuri.org/Oscar/OscarExceptionInfo.xsd", "OscarException"},
                        xml-type = {XMLName "http://temp.openuri.org/Oscar/OscarExceptionInfo.xsd", "OscarExceptionType"},
                        curl-type = OscarExceptionType
                    },
                    {SOAPObjectType
                        element-name = {XMLName "http://temp.openuri.org/Oscar/OscarExceptionInfo.xsd", "OscarExceptionInfo"},
                        xml-type = {XMLName "http://temp.openuri.org/Oscar/OscarExceptionInfo.xsd", "OscarExceptionInfoType"},
                        curl-type = OscarExceptionInfoType,
                        nillable? = true
                    }
                },
                element-names =
                    {{Array-of #XMLName}
                        {XMLName "http://temp.openuri.org/Oscar/OscarExceptionInfo.xsd", "OscarException"}
                    },
                xml-type-to-curl-type = xml-type-to-curl-type,
                curl-type-to-xml-type = curl-type-to-xml-type,
                xml-type-to-element-name = xml-type-to-element-name
            }
        {array-marshaler.register
            type-mapper = type-mapper,
            element-name-to-xml-type-mapper = element-name-to-xml-type,
            xml-type-to-curl-type-mapper = xml-type-to-curl-type,
            curl-type-to-xml-type-mapper = curl-type-to-xml-type,
            xml-type-to-element-name-mapper = xml-type-to-element-name
        }
    }
    {do
        let constant soap-struct-marshaler:SOAPStructMarshaler =
            {SOAPStructMarshaler
                {SOAPObjectType
                    element-name = {XMLName "http://temp.openuri.org/Oscar/OscarExceptionInfo.xsd", "OscarException"},
                    xml-type = {XMLName "http://temp.openuri.org/Oscar/OscarExceptionInfo.xsd", "OscarExceptionType"},
                    curl-type = OscarExceptionType,
                    nillable? = true
                },
                {{Array-of #XMLName}
                    {XMLName "http://temp.openuri.org/Oscar/OscarExceptionInfo.xsd", "code"},
                    {XMLName "http://temp.openuri.org/Oscar/OscarExceptionInfo.xsd", "caption"},
                    {XMLName "http://temp.openuri.org/Oscar/OscarExceptionInfo.xsd", "message"}
                },
                {{Array-of SOAPObjectType}
                    {SOAPObjectType
                        xml-type = {XMLName SOAPTypeMapper.xml-schema-uri, "string"},
                        curl-type = String
                    },
                    {SOAPObjectType
                        xml-type = {XMLName SOAPTypeMapper.xml-schema-uri, "string"},
                        curl-type = String
                    },
                    {SOAPObjectType
                        xml-type = {XMLName SOAPTypeMapper.xml-schema-uri, "string"},
                        curl-type = String
                    }
                },
                {{Array-of String}
                    "code",
                    "caption",
                    "message"
                },
                element-name-to-xml-type = element-name-to-xml-type,
                xml-type-to-curl-type = xml-type-to-curl-type,
                curl-type-to-xml-type = curl-type-to-xml-type,
                xml-type-to-element-name = xml-type-to-element-name
            }
        {soap-struct-marshaler.register
            type-mapper = type-mapper,
            element-name-to-xml-type-mapper = element-name-to-xml-type,
            xml-type-to-curl-type-mapper = xml-type-to-curl-type,
            curl-type-to-xml-type-mapper = curl-type-to-xml-type,
            xml-type-to-element-name-mapper = xml-type-to-element-name
        }
    }
    {do
        let constant array-marshaler:SOAPArrayMarshaler =
            {SOAPArrayMarshaler.from-element-type-array
                {{Array-of SOAPObjectType}
                    {SOAPObjectType
                        element-name = {XMLName "http://temp.openuri.org/Oscar/OscarWarningInfo.xsd", "OscarWarning"},
                        xml-type = {XMLName "http://temp.openuri.org/Oscar/OscarWarningInfo.xsd", "OscarWarningType"},
                        curl-type = OscarWarningType
                    },
                    {SOAPObjectType
                        element-name = {XMLName "http://temp.openuri.org/Oscar/OscarWarningInfo.xsd", "OscarWarningInfo"},
                        xml-type = {XMLName "http://temp.openuri.org/Oscar/OscarWarningInfo.xsd", "OscarWarningInfoType"},
                        curl-type = OscarWarningInfoType,
                        nillable? = true
                    }
                },
                element-names =
                    {{Array-of #XMLName}
                        {XMLName "http://temp.openuri.org/Oscar/OscarWarningInfo.xsd", "OscarWarning"}
                    },
                xml-type-to-curl-type = xml-type-to-curl-type,
                curl-type-to-xml-type = curl-type-to-xml-type,
                xml-type-to-element-name = xml-type-to-element-name
            }
        {array-marshaler.register
            type-mapper = type-mapper,
            element-name-to-xml-type-mapper = element-name-to-xml-type,
            xml-type-to-curl-type-mapper = xml-type-to-curl-type,
            curl-type-to-xml-type-mapper = curl-type-to-xml-type,
            xml-type-to-element-name-mapper = xml-type-to-element-name
        }
    }
    {do
        let constant soap-struct-marshaler:SOAPStructMarshaler =
            {SOAPStructMarshaler
                {SOAPObjectType
                    element-name = {XMLName "http://temp.openuri.org/Oscar/OscarWarningInfo.xsd", "OscarWarning"},
                    xml-type = {XMLName "http://temp.openuri.org/Oscar/OscarWarningInfo.xsd", "OscarWarningType"},
                    curl-type = OscarWarningType,
                    nillable? = true
                },
                {{Array-of #XMLName}
                    {XMLName "http://temp.openuri.org/Oscar/OscarWarningInfo.xsd", "code"},
                    {XMLName "http://temp.openuri.org/Oscar/OscarWarningInfo.xsd", "caption"},
                    {XMLName "http://temp.openuri.org/Oscar/OscarWarningInfo.xsd", "message"}
                },
                {{Array-of SOAPObjectType}
                    {SOAPObjectType
                        xml-type = {XMLName SOAPTypeMapper.xml-schema-uri, "string"},
                        curl-type = String
                    },
                    {SOAPObjectType
                        xml-type = {XMLName SOAPTypeMapper.xml-schema-uri, "string"},
                        curl-type = String
                    },
                    {SOAPObjectType
                        xml-type = {XMLName SOAPTypeMapper.xml-schema-uri, "string"},
                        curl-type = String
                    }
                },
                {{Array-of String}
                    "code",
                    "caption",
                    "message"
                },
                element-name-to-xml-type = element-name-to-xml-type,
                xml-type-to-curl-type = xml-type-to-curl-type,
                curl-type-to-xml-type = curl-type-to-xml-type,
                xml-type-to-element-name = xml-type-to-element-name
            }
        {soap-struct-marshaler.register
            type-mapper = type-mapper,
            element-name-to-xml-type-mapper = element-name-to-xml-type,
            xml-type-to-curl-type-mapper = xml-type-to-curl-type,
            curl-type-to-xml-type-mapper = curl-type-to-xml-type,
            xml-type-to-element-name-mapper = xml-type-to-element-name
        }
    }
    <#recurse doc>

	<#macro root>  
	<#recurse>
	</#macro>
	
	<#macro node>
	<#assign name = .node.@name>
	<#assign type = .node.@type>
	<#if type = "map">
	{do
	    let constant soap-struct-marshaler:SOAPStructMarshaler =
	        {SOAPStructMarshaler
	            {SOAPObjectType
	                element-name = {XMLName "http://temp.openuri.org/Oscar/${docno}.xsd", "${name}"},
	                xml-type = {XMLName "http://temp.openuri.org/Oscar/${docno}.xsd", "${name}"},
	                curl-type = ${name?replace("_","-")?capitalize},
	                nillable? = true
	            },
	            {{Array-of #XMLName}
	            	<#recurse using xml_re>                 
	            },
	            {{Array-of SOAPObjectType}
	            	<#recurse using obj_re>                  
	            },
	            {{Array-of String}
	                <#recurse using name_re>  
	            },
	            element-name-to-xml-type = element-name-to-xml-type,
	            xml-type-to-curl-type = xml-type-to-curl-type,
	            curl-type-to-xml-type = curl-type-to-xml-type,
	            xml-type-to-element-name = xml-type-to-element-name
	        }
	        {soap-struct-marshaler.register
	            type-mapper = type-mapper,
	            element-name-to-xml-type-mapper = element-name-to-xml-type,
	            xml-type-to-curl-type-mapper = xml-type-to-curl-type,
	            curl-type-to-xml-type-mapper = curl-type-to-xml-type,
	            xml-type-to-element-name-mapper = xml-type-to-element-name
	        }
	}
	<#elseif type="list">
		list
	</#if>
	<#if .node?node_name = "node">
	<#recurse>
	</#if>
	</#macro>
	
	<#macro element>	
	</#macro>
    

